package com.jiyinit.web.core.business.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.business.dto.MessageRequest;
import com.jiyinit.web.core.business.dto.TaskMessageRequest;
import com.jiyinit.web.core.business.dto.UserRequest;
import com.jiyinit.web.core.business.entity.TabCoreTask;
import com.jiyinit.web.core.business.entity.TabCoreTaskMessage;
import com.jiyinit.web.core.business.entity.TabCoreUserTask;
import com.jiyinit.web.core.business.vo.TaskInfoVo;
import com.jiyinit.web.core.business.vo.TaskMessageVo;
import com.jiyinit.web.core.business.vo.UserInfoVo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * <p></p>
 * <p/>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author wuyuefeng
 * @version 1.0
 * @date 2017/4/11 17:51
 * @since 1.0
 */
@Repository("core.tabCoreTaskMessageDao")
public class TabCoreTaskMessageDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabCoreTaskMessageDao.class);

    private String SQLID = "core.tabCoreTaskMessageDao.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;

    public List<TabCoreTaskMessage> findNewMessageList(List<TaskInfoVo> list){
        return mybatisDaoContext.findAll(SQLID+"findNewMessageList",TabCoreTaskMessage.class,list);
    }

    public int update(TabCoreTaskMessage message){
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKeySelective",message);
    }

    public TabCoreTaskMessage findByPK(Integer id){
        return mybatisDaoContext.findOne(SQLID+"selectByPrimaryKey",TabCoreTaskMessage.class,id);
    }

    public TabCoreTaskMessage findTodayMessage(Integer taskId){
        return mybatisDaoContext.findOne(SQLID+"findTodayMessage",TabCoreTaskMessage.class,taskId);
    }

    public PagingResult<TaskMessageVo> findByPage(MessageRequest request){
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID+"findByPage",TaskMessageVo.class,request.getId(),pageBounds);
    }

    /**
     * 
         * 说明
         * @author wuyuefeng
         * @create 2017年4月25日 下午5:51:19
         * @param 
         * @return
     */
    public List<TaskMessageVo> findTaskMessageByTaskId(Integer taskId){
        return mybatisDaoContext.findAll(SQLID + "selectByTaskId", TaskMessageVo.class, taskId);
    }
    
    
    public List<TaskMessageVo> findAllTaskMessageByTaskId(Integer taskId){
        return mybatisDaoContext.findAll(SQLID + "selectAllByTaskId", TaskMessageVo.class, taskId);
    }
    
    
    /**
     * 说说分页
     * @param taskMessageRequest
     * @return
     */
    public PagingResult<TaskMessageVo> messageForPage(TaskMessageRequest taskMessageRequest){
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(taskMessageRequest.getLimit());
        pageBounds.setPage(taskMessageRequest.getPage());
        return mybatisDaoContext.findForPage(SQLID + "selectAllByTaskId", TaskMessageVo.class, taskMessageRequest.toMap(), pageBounds);
    }
    
    
    
    public List<TaskMessageVo> findTaskMesByTaskId(TaskMessageRequest taskMessageRequest){
    	Map<String, Object> map = new HashMap<String, Object>();
        map.put("taskId", taskMessageRequest.getTaskId());
        map.put("sort", taskMessageRequest.getSort());
        return mybatisDaoContext.findAll(SQLID + "selectAllByTaskId", TaskMessageVo.class, map);
    }
    
    /**
     * 
         * 说明
         * @author wuyuefeng
         * @create 2017年5月12日 上午11:53:30
         * @param 
         * @return
     */
    public int addTaskMessage(TabCoreTaskMessage TabCoreTaskMessage) {
        return mybatisDaoContext.save(SQLID + "insertSelective", TabCoreTaskMessage);
    }
    /**
     * 
         * 说明
         * @author wuyuefeng
         * @create 2017年5月23日 上午10:32:51
         * @param 
         * @return
     */
    public List<TaskMessageVo> findTaskMessageByParentId(Integer parentId){
        return mybatisDaoContext.findAll(SQLID + "selectByParentId", TaskMessageVo.class, parentId);
    }
    
}
